package com.levy.contronller.javaWeb.threadMasterWorker;


import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Worker implements Runnable {
    private ConcurrentLinkedQueue<Task> wokerQueue;
    private ConcurrentHashMap<String, Object> resultMap;

    public void setWorkerQueue(ConcurrentLinkedQueue<Task> workerQueue) {
        this.wokerQueue = workerQueue;
    }

    public void setResultMap(ConcurrentHashMap<String, Object> resultMap) {
        this.resultMap = resultMap;
    }

    @Override
    public void run() {
        while (true) {
            Task task = this.wokerQueue.poll();
            if (task == null) {
                break;
            }
            //真正的业务处理
            Object output = MyWorker.handle(task);

            this.resultMap.put(Integer.toString(task.getId()),output);

        }
    }


    public static Object handle(Task input){
        return null;
    }




}
